package com.dht.xiao.jianye.http;

import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.dht.xiao.jianye.base.BaseBean;
import com.dht.xiao.jianye.base.BaseUrls;
import com.dht.xiao.jianye.bean.AddFacilityBean;
import com.dht.xiao.jianye.bean.CollectorBean;
import com.dht.xiao.jianye.bean.CollectorFacilityBean;
import com.dht.xiao.jianye.bean.DeviceStaffBean;
import com.dht.xiao.jianye.bean.EmptyCaseBean;
import com.dht.xiao.jianye.bean.EndReadBean;
import com.dht.xiao.jianye.bean.FacilitySettingBean;
import com.dht.xiao.jianye.bean.GetFacilityBean;
import com.dht.xiao.jianye.bean.MyCaseBean;
import com.dht.xiao.jianye.bean.QueryCaseBean;
import com.dht.xiao.jianye.bean.SimpleBean;
import com.dht.xiao.jianye.bean.StaffLoginBean;
import com.dht.xiao.jianye.bean.newdata.DepartmentsBean;
import com.dht.xiao.jianye.bean.newdata.HospitalBean;
import com.dht.xiao.jianye.bean.newdata.LoginNewBean;
import com.dht.xiao.jianye.bean.newdata.OfficeBean;
import com.dht.xiao.jianye.bean.newdata.ProductListBean;
import com.dht.xiao.jianye.bean.newdata.RfidQueryBean;
import com.dht.xiao.jianye.bean.newdata.SpecListBean;
import com.dht.xiao.jianye.bean.newdata.UserBean;
import com.dht.xiao.jianye.bean.phoneBean;
import com.dht.xiao.jianye.utils.Information;
import com.dht.xiao.jianye.utils.UserHelper;
import com.lzy.okgo.model.HttpParams;

import cn.dlc.commonlibrary.okgo.OkGoWrapper;
import io.reactivex.Observable;

/**
 * Created by Administrator on 2019/4/4.
 */

public class MainHttp {
    private final OkGoWrapper mOkGoWrapper;

    private MainHttp() {
        mOkGoWrapper = OkGoWrapper.instance();
    }

    private static class InstanceHolder {
        private static final MainHttp sInstance = new MainHttp();
    }

    public static MainHttp get() {
        return InstanceHolder.sInstance;
    }
    private String getToken() {
        return UserHelper.get().getToken();
    }
    /**
     * 登陆
     * @return
     */
    public Observable<LoginNewBean> login(String account, String password) {
        HttpParams params = new HttpParams();
        params.put("account", account);
        params.put("password", password);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"login", params, LoginNewBean.class);
    }
    /**
     * 开始读取
     * @return
     */
    public Observable<SimpleBean> beginRead(String series,String macType) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        params.put("macType", macType);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"beginRead", params, SimpleBean.class);
    }

    /**
     * 读取结果
     * @return
     */
    public Observable<EndReadBean> endRead(String series,String type,String macType,String caseNo) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        params.put("type", type);//1投递，2领取，3绑定
        params.put("macType", macType);
        if (!TextUtils.isEmpty(caseNo)) {
            params.put("caseNo", caseNo);
        }

        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"endRead", params, EndReadBean.class);
    }

    /**
     * 确认回收
     * @return
     */
    public Observable<SimpleBean> recycle(String series,int confirm) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        if (confirm != 0) {
            params.put("confirm", confirm);
        }
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"recycle", params, SimpleBean.class);
    }

    /**
     * 开门
     * @return
     */
    public Observable<SimpleBean> opendoor(String series) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"open", params, SimpleBean.class);
    }
    /**
     * 关门
     * @return
     */
    public Observable<SimpleBean> closedoor(String series) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"close", params, SimpleBean.class);
    }

    /**
     * 获取空柜
     * @return
     */
    public Observable<EmptyCaseBean> emptyCase(String series) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"emptyCase", params, EmptyCaseBean.class);
    }

    /**
     * 领取结果
     * @return
     */
    public Observable<MyCaseBean> myCase(String series) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"myCase", params, MyCaseBean.class);
    }

    /**
     * 员工登录
     * @return
     */
    public Observable<StaffLoginBean> staffLogin(String account, String password) {
        HttpParams params = new HttpParams();
        params.put("account",account);
        params.put("password", password);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"staffLogin", params, StaffLoginBean.class);
    }
    /**
     * 柜内人员
     * @return
     */
    public Observable<DeviceStaffBean> deviceStaff(String series) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"deviceStaff", params, DeviceStaffBean.class);
    }

    /**
     * 查询结果
     * @return
     */
    public Observable<QueryCaseBean> queryCase(String series, String staffId, String caseNo) {
        HttpParams params = new HttpParams();
        params.put("series", series);
        if (!TextUtils.isEmpty(staffId)) {
            params.put("staffId", staffId);
        }
        if (!TextUtils.isEmpty(caseNo)) {
            params.put("caseNo", caseNo);
        }
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"queryCase", params, QueryCaseBean.class);
    }


    /**
     * 绑定标签
     *
     * @param productId 产品id
     * @param rfids rfid
     * @return
     */
    public Observable<SimpleBean> bindRFID(int productId,int departments_Id,int user_id, String rfids) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
        httpParams.put("goods_id", productId);
        httpParams.put("office_id", departments_Id);
        if (user_id != 0){
            httpParams.put("user_id", user_id);
        }
//        StringBuilder sb = new StringBuilder();
//        for (int i = 0; i < rfids.length; i++) {
//
//            sb.append(rfids[i]);
//
//            if (i != rfids.length - 1) {
//                sb.append(',');
//            }
//        }
        httpParams.put("rfids", rfids);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"rfidBind", httpParams, SimpleBean.class);
      //  return rxPost("rfid_bind", httpParams, SimpleBean.class, true, null);
    }

    /**
     * 获取规格分类
     * @return
     */
    public Observable<SpecListBean> categorys() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
/*        httpParams.put("category_id", category);
        httpParams.put("id", specId);*/
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"categorys", httpParams, SpecListBean.class);
       // return rxPost("spec", httpParams, SpecListBean.class, true, error);
    }

     /** 获取分类下的产品列表
     *
     * @return
             */
    public Observable<ProductListBean> goods1(int category) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
        httpParams.put("category_id", category);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"goods", httpParams, ProductListBean.class);
        //return rxPost("goods", httpParams, ProductListBean.class, true, error);
    }

    /**
     * 医院列表
     * @param hotel_id
     * @return
     */
    public Observable<HospitalBean> gethotel(int hotel_id) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
        if (hotel_id != 0) {
            httpParams.put("hotel_id", hotel_id);
        }
       // return rxPost("hotel", httpParams, HospitalBean.class, true, error);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"hotel", httpParams, HospitalBean.class);
    }

    /**
     *科室列表
     * @param office_id
     * @return
     */
    public Observable<DepartmentsBean> getDepartments(int hotel_id, int office_id) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
        if (hotel_id != 0) {
            httpParams.put("hotel_id", hotel_id);
        }
        if (office_id != 0) {
            httpParams.put("office_id", office_id);
        }
       // return rxPost("office", httpParams, DepartmentsBean.class, true, error);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"office", httpParams, DepartmentsBean.class);
    }

    /**
     *人员列表
     * @param hotel_id
     * @return
     */
    public Observable<UserBean> getUser(int hotel_id, int office_id) {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
        if (hotel_id != 0) {
            httpParams.put("hotel_id", hotel_id);
        }
        if (office_id != 0) {
            httpParams.put("office_id", office_id);
        }
      //  return rxPost("user", httpParams, UserBean.class, true, error);
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"staff", httpParams, UserBean.class);
    }

    /**
     * 科室
     * @return
     */
    public Observable<OfficeBean> getOffice() {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());

        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"office", params, OfficeBean.class);
    }


    /** 获取分类下的产品列表
     *
     * @return
     */
    public Observable<ProductListBean> goods() {
        HttpParams httpParams = new HttpParams();
        httpParams.put("sign", getToken());
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"goods", httpParams, ProductListBean.class);
        //return rxPost("goods", httpParams, ProductListBean.class, true, error);
    }

    /**
     * 查询
     * @return
     */
    public Observable<RfidQueryBean> rfidQuery(String series, String office_id, String goods_id) {
        HttpParams params = new HttpParams();
        params.put("sign", getToken());
        params.put("series", series);
        if (!TextUtils.isEmpty(office_id)) {
            params.put("office_id", office_id);
        }
        if (!TextUtils.isEmpty(goods_id)) {
            params.put("goods_id", goods_id);
        }
        return mOkGoWrapper.rxPostBean01(BaseUrls.BASRIMG+"rfidQuery", params, RfidQueryBean.class);
    }


}
